package be.gwi.alfresco.run.model.comparator;

import java.util.Comparator;

import be.gwi.alfresco.run.model.RunType;
import be.gwi.alfresco.run.model.Runner;

/**
 * A Runner comparator.
 * <p>
 * Compares runners.
 * 
 * @author gabriel.willems@gmail.com
 * 
 * @version 1.0
 * @since 1.0
 */
public class RunnerComparator implements Comparator<Runner> {
    private RunType runType;

    /**
     * Constructor
     * 
     * @param runType
     */
    public RunnerComparator(RunType runType) {
        this.runType = runType;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(Runner runner1, Runner runner2) {
        switch (runType) {
        case RUNNING:
            return runner1.getRunningDistance().compareTo(runner2.getRunningDistance());
        case CYCLING:
            return runner1.getCyclingDistance().compareTo(runner2.getCyclingDistance());
        case SWIMMING:
            return runner1.getSwimmingDistance().compareTo(runner2.getSwimmingDistance());
        default:
            return runner1.getRunPoint().compareTo(runner2.getRunPoint());  
        }
    }
}